package com.company.cloud.common.mq.redis.client.util;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ThrowableUtil {
	
	 /**
     * parse error to string
     * @param e
     * @return
     */
    public static String toString(Throwable e) {
        StringWriter stringWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(stringWriter));
        String errorMsg = stringWriter.toString();
        return errorMsg;
    }
    
    
    public static boolean isNoGroupError(Exception e) {
    	return isNoGroupError(e.getMessage());
    }
    
    public static boolean isNoGroupError(String errorMsg) {
//     	boolean flag= errorMsg.contains("NOGROUP");
     	if(errorMsg.contains("NOGROUP") && errorMsg.contains("XREADGROUP")) {
     		return true;
     	}else {
     		return false;
     	}
    }
    
    public static void main(String[] args) {
    	String errorMsg=" NOGROUP No such key 'mq' or consumer group 'g7' in XREADGROUP with GROUP option";
    	
//    	 NOGROUP No such key 'Topic:PayNotity:JBH_Pay_01' or consumer group 'DEFAULT' in XREADGROUP with GROUP 
    	
//    	 ERR The XGROUP subcommand requires the key to exist.
//    	 Note that for CREATE you may want to use the MKSTREAM option to create an empty stream automatically.,
    	
    	System.out.println(ThrowableUtil.isNoGroupError(errorMsg));
    	
	}

}
